﻿CREATE PROCEDURE [dbo].[usp_UserApplication_Upd]
@ID INT, @NTUserName VARCHAR (50), @ApplicationName VARCHAR (256), @TimeStmp TIMESTAMP=NULL
AS
BEGIN

DECLARE @ErrorCode AS INT
DECLARE @RowsAffected AS INT

UPDATE [UserApplication] WITH (ROWLOCK) SET
       [NTUserName] = @NTUserName,
       [ApplicationName] = @ApplicationName
    WHERE ([ID] = @ID) AND ([TimeStmp] = @TimeStmp)
    OPTION (FAST 1)

SELECT @ErrorCode = @@ERROR, @RowsAffected = @@ROWCOUNT

IF @RowsAffected = 0
    RETURN 50001  -- concurrency violation

SELECT [ID], [NTUserName], [ApplicationName], [TimeStmp], [CreateDt], [CreateUid], [RevMdlName], [RevDt], [RevUid] FROM [UserApplication]
    WHERE ([ID] = @ID)

RETURN @ErrorCode

END

